home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 16905 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.7 KB

  1. Path: fido.asd.sgi.com!news
  2. From: austern@isolde.mti.sgi.com (Matt Austern)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Why don't you use garbage collection
  5. Date: 12 Apr 1996 16:56:52 GMT
  6. Organization: SGI
  7. Distribution: world
  8. Message-ID: <AUSTERN.96Apr12095652@isolde.mti.sgi.com>
  9. References: <316D291F.465D@sto.fdata.se> <1996Apr12.170708.1835@ittpub>
  10. Reply-To: austern@mti.sgi.com
  11. NNTP-Posting-Host: isolde.mti.sgi.com
  12. In-reply-to: wil@ittpub.nl's message of 12 Apr 96 17:07:07 WET
  13.  
  14. In article <1996Apr12.170708.1835@ittpub> wil@ittpub.nl (Wil Evers) writes:
  15.  
  16. > In my opinion, this subtle difference is why garbage collection would be  
  17. > appropriate for C, but not for C++. C++ destructors are often used to  
  18. > release other resources than memory. If C++ programmers would get sloppy  
  19. > about deleting their heap objects ("don't worry about deleting it, the  
  20. > collector will do it for you"), we might end up with too many open file  
  21. > descriptors, eternal database locks, forever blocking semaphores and  
  22. > expensive telephone bills.
  23.  
  24. In C++, I think the most reasonable scenerio is where some objects,
  25. but not all, are garbage collected.  You might, for example, inherit
  26. from some GC_Base mixin class if you want garbage collection; GC_Base
  27. would overload operator new to do the appropriate magic.  And it's
  28. entirely reasonable to imagine that you would have to accept some
  29. restrictions (such as restrictions on destructors) in exchange for
  30. garbage collection.
  31.  
  32. In C++ we're used to the idea that heap-allocated and stack-allocated
  33. objects have different rules.  It's not so radical to introduce
  34. garbage-collected objects as a third category.
  35. -- 
  36. Matt Austern
  37. SGI: MTI Compilers Group
  38. austern@isolde.mti.sgi.com
  39.